package com.fy.service.imbusiness.controller;

import com.fy.common.dto.ReportDto;
import com.fy.common.entity.SkImReport;
import com.fy.common.util.TokenUtil;
import com.fy.framework.common.model.R;
import com.fy.framework.component.config.LocaleMessage;
import com.fy.service.service.SkImReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhshuo
 * @date 2021/12/27 14:34
 */
@Slf4j
@RestController
@AllArgsConstructor
@Api(tags = "举报")
@RequestMapping("/report")
public class SkImReportController {

    LocaleMessage localeMessage;

    SkImReportService skImreportService;

    @PostMapping
    @ApiOperation("举报")
    public R<?> report(@RequestBody ReportDto reportDto ){
        try {
            skImreportService.insert(new SkImReport().setContent(reportDto.getContent()).setSkImUserId(TokenUtil.getUserId()).setTargetId(reportDto.getTargetId())
                    .setTargetType(reportDto.getType()));
            return R.success(localeMessage.getMessage("im.common.successful"));
        } catch (Exception e) {
            log.error("error",e.getCause());
            return R.failedAlter(localeMessage.getMessage("im.common.failed"));
        }
    }

}
